/// <reference path="../sage/sage.util.js" />
/// <reference path="../sage/sage.input.__.base.js" />
/// <reference path="../sage/sage.input.objectlocation.js" />
/// <reference path="../sage/sage.input.ZZ.singletons.js" />

var FourKillGameView_Tap = Base.extend({
    initialize: function initialize() {
        this.moveBuffer = 0;
        this.x = 0;
        this.y = 0;
        this.enabled = false;
    },
    isAvailable: function isAvailable() {
        return true;
    },
    enable: function enable() {
        if (!this.enabled && GlobalInputHandlers.Tap.isAvailable() && GlobalInputHandlers.Tap.enabled) {
            this.enabled = true;
            var self = this;
            GlobalInputHandlers.Tap.subscribe("FourKillGameView.Tap", self);
        }
    },
    disable: function disable() {
        if (this.enabled) {
            this.enabled = false;
            GlobalInputHandlers.Tap.unsubscribe("FourKillGameView.Tap");
        }
    },
    fireEvent: function fireEvent(eventName, data) {
        if (eventName == "vclick") {
            this.x = data.clientX;
            this.y = data.clientY;
            this.moveBuffer = 20;
            if (data.prevent) data.preventDefault();
        }
    },
    update: function update(context) {
        var camera = context.camera;

        if (this.moveBuffer > 0) {
            var xm = context.viewPort.size.w / 7;
            var ym = context.viewPort.size.h / 5;
            var yv = 1;

            if (this.y > ym * 4) yv = -1;
            else if (this.y > ym * 3) yv = -0.5;
            else if (this.y > ym * 2) yv = 0.5;

            if (this.x < xm) camera.turn(util.radians(2));
            else if (this.x < xm * 3) camera.turn(util.radians(0.5));
            else if (this.x > (xm * 6)) camera.turn(util.radians(-2));
            else if (this.x > (xm * 4)) camera.turn(util.radians(-0.5));

            if (this.moveBuffer > 12) camera.move(5 * yv);
            else if (this.moveBuffer > 10) camera.move(3 * yv);
            else if (this.moveBuffer > 6) camera.move(2 * yv);
            else camera.move(1 * yv);
            this.moveBuffer--;
        }
    }
});
